package com.project.controller;

import com.alibaba.fastjson2.JSON;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.StringUtils;
import com.project.bean.TicketBean;
import com.project.service.CinemaService;
import com.project.service.IMtTicketService;
import com.project.util.Verifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("mtTicket")
public class MtTicketController {
    @Autowired
    private CinemaService cinemaService;
    @Autowired
    private IMtTicketService mtTicketService;

    /**
     * 从电影院拉取新上市的电影
     *
     * @return
     */
//    @GetMapping("updateTicket")
    @Scheduled(cron = "0 11 22 ? * *")
    public String updateTicket() {
        System.out.println("开始");
        List<TicketBean> list = cinemaService.getTicketByStatus("新上市");
        System.out.println(list.size());
        if (list.size() != 0) {
            for (int i = 0; i < list.size(); i++) {
                TicketBean ticket = list.get(i);
                mtTicketService.add(ticket.getMovieName(), ticket.getPrice(), ticket.getNumber());
            }
        }
        return "ok";
    }

    /**
     * 拉取美团所有的电影票，进行页面展示
     *
     * @return
     */
    @GetMapping("mtTicketAll")
    public Object mtTicketAll(Integer pageNO) {
//        String token = request.getHeader("token");
//        String str=  Verifier.verifierJwt(token);
//        if (StringUtils.hasLength(str)) {
            return mtTicketService.mtTicketAll(pageNO);
//        } else {
//            return null;
//        }

    }
}
